# -*- coding: UTF-8 -*-
__author__ = 'kidozh'

import tornado.web
import re
class urlModule(tornado.web.UIModule):
    def render(self,uimodule):
        from conf.urls import urlPackage
        from conf import setting
        Setting = setting()
        Setting._setup()

        urlMapper = urlPackage(Setting._wrapped.ROOT_URLCONF)
        urlHandler = urlMapper.detectURL()
        for url,moduleStr in urlHandler:
            if moduleStr == uimodule:
                purifyURL = re.match(r'\W+(/.+)$',url)
                return purifyURL.group(1)
        return ''

class optionModule(tornado.web.UIModule):
    def render(self,option):
        from conf.urls import urlPackage
        from conf import setting
        Setting = setting()
        Setting._setup()

        return getattr(Setting._wrapped,option,'')